# Contributor: Jeff Bilyk <jbilyk@gmail.com>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Milan P. Stanić <mps@arvanta.net>
pkgname=haproxy
# NOTE: Upgrade only to LTS versions announced on upstream site url!
# Using LTS versions is easier to keep it in good shape for stable releases
pkgver=2.2.2
_pkgmajorver=${pkgver%.*}
pkgrel=1
pkgdesc="A TCP/HTTP reverse proxy for high availability environments"
url="https://www.haproxy.org/"
arch="all"
license="GPL-2.0-or-later LGPL-2.1-or-later"
_luaver="5.3"
options="!check"  # FIXME: depends on vtest
makedepends="pcre-dev openssl-dev linux-headers lua$_luaver-dev zlib-dev"
install="haproxy.pre-install haproxy.pre-upgrade"
subpackages="$pkgname-doc $pkgname-openrc"
source="https://www.haproxy.org/download/$_pkgmajorver/src/haproxy-$pkgver.tar.gz
	haproxy.initd
	haproxy.cfg"

# secfixes:
#   2.1.4-r0:
#     - CVE-2020-11100

build() {
	case "$CARCH" in mips|mipsel*) _carchflags="ADDLIB=-latomic";; esac
	make \
	     $_carchflags \
	     TARGET=linux-musl \
	     USE_PCRE=1 \
	     USE_OPENSSL=1 \
	     USE_ZLIB=1 \
	     USE_LUA=1 \
	     USE_NS=1 \
	     LUA_LIB=/usr/lib/lua$_luaver \
	     LUA_INC=/usr/include/lua$_luaver \
	     EXTRA_OBJS="contrib/prometheus-exporter/service-prometheus.o" \
	     CFLAGS="$CFLAGS"
}

check() {
	make reg-tests
}

package() {
	make install \
	     DESTDIR="$pkgdir" PREFIX=/usr DOCDIR=/usr/share/doc/haproxy
	install -d \
	        "$pkgdir"/var/lib/haproxy
	install -D -m 755 \
	        "$srcdir"/$pkgname.initd \
	        "$pkgdir"/etc/init.d/$pkgname
	install -D -m 644 \
	        "$srcdir"/haproxy.cfg \
	        "$pkgdir"/etc/haproxy/haproxy.cfg
}

sha512sums="da76bd01c9b1c806145df133f6844798eecf6152b968e1739bcf5f9f87b41c1b0190484d033b310b2f0d4fddf48c036243ce8670a5668a9021f8496946094a39  haproxy-2.2.2.tar.gz
3ab277bf77fe864ec6c927118dcd70bdec0eb3c54535812d1c3c0995fa66a3ea91a73c342edeb8944caeb097d2dd1a7761099182df44af5e3ef42de6e2176d26  haproxy.initd
26bc8f8ac504fcbaec113ecbb9bb59b9da47dc8834779ebbb2870a8cadf2ee7561b3a811f01e619358a98c6c7768e8fdd90ab447098c05b82e788c8212c4c41f  haproxy.cfg"
